'use strict';
const orderState = require('../../../../../application/service/orderState.js')
const applicationConstant = require('../../../../../application/constant/applicationsConstant.js')
const businessState = require('../../../../../application/service/businessState.js')
const orderPaySuccess = require('../../../../../application/service/orderPaySuccess.js');
module.exports = {
	/**
	 * 购买会员
	 * @url client/order/kh/create/role 前端调用的url参数地址
	 * data 请求参数
	 * @param {String} params1  参数1
	 */
	main: async (event) => {
		let { data = {}, userInfo, util, filterResponse, originalParam } = event;
		let { customUtil, uniID, config, pubFun, vk, db, _ } = util;
		let { uid } = data;
		let res = { code: 0, msg: "" };
		// 业务逻辑开始-----------------------------------------------------------

		//数据准备
		let promoCodeId = ""

		let platform = data.platform

		let role = await vk.baseDao.findById({
			dbName: "uce-vip-role",
			id: data._id,
			whereJson: {
				status: true
			}
		});
		//不存在
		if (!role) {
			res.code = -1
			res.msg = "无效的会员"
			return res;
		}


		let type = applicationConstant.ROLE
		let total = role.charge * 100
		let title = role.name
		let goods_item = [{
			'oid': null,
			'user_id': uid,
			'goods_id': role._id,
			'charge': role.charge * 100,
			'type': type,
			'num': 1,
			'goods_name': title,
		}]

		//统一创建订单
		res = await orderState.createOrder(event, uid, total, title, type, platform, goods_item, promoCodeId)

		// 业务逻辑结束-----------------------------------------------------------
		return res;
	}
}
